package com.qf.lanzhou.blog.api.controller;

import com.qf.lanzhou.blog.api.pojo.entity.Article;
import com.qf.lanzhou.blog.api.pojo.entity.User;
import com.qf.lanzhou.blog.api.service.PraiseArticlepsService;
import com.qf.lanzhou.blog.api.service.impl.PraiseArticlepsServiceimpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author jian   个人中心文章点赞具体内容
 * @Date 2020/12/21 15:07
 * @JDK 1.8
 * @Version 1.0
 */
@WebServlet("/PraiseArticleps.do")
public class PraiseArticlepsServlet extends BaseServletPost{
    private PraiseArticlepsService praiseArticlepsService=new PraiseArticlepsServiceimpl();

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //解决请求的乱码
        req.setCharacterEncoding("utf-8");
        //解决响应乱码
        resp.setContentType("text/html;charset=utf-8");

        User user1 = (User) req.getSession().getAttribute("user");
        Long id = user1.getId();
        //转为string类型
        String userId = id + "";
        //String userId = req.getParameter("userId");

        List<Article> list=praiseArticlepsService.selectArticle(userId);
        System.out.println(list);
        ArrayList<Object> list1 = new ArrayList<>();
        for (int j = 0; j <list.size() ; j++) {
            Article article = list.get(j);
            long articleId = article.getArticleId();
            String articleName = article.getArticleName();
            String articleContain = article.getArticleContain();
            list1.add(articleId);
            list1.add(articleName);
            list1.add(articleContain);
        }
        System.out.println(list1);
        successResultWrite(list1,resp);
    }
}
